package com.bao123.chatroom.chat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 聊天用的webSocket
 * @author lbw
 */
@Slf4j
@Component
@ServerEndpoint("/websocket/{name}")
public class ChatWebSocket {
    /**
     * 与某个客户端的连接对话，需要通过它来给客户端发送消息
     */
    private Session session;
    /**
     * 标识当前连接客户端的用户名
     */
    private String name;
    /**
     * 用于存储所有连接服务的客户端
     */
    private static ConcurrentHashMap<String, ChatWebSocket> webSocketMap = new ConcurrentHashMap<>();

    @OnOpen
    public void OnOpen(Session session, @PathParam(value = "name") String name){
        this.session = session;
    }

}
